Create a function which takes a string of all lowercase, return a string with First Later
uppercase.
changeCase("i love india") II Output : I Love India.
const newStr = (str) => str.split(" ").map(e => e[0].toUpperCase() + e.slice(1)).join(" ");
document.getElementById("ex1").innerText = newStr("i love india");
Create a function which counts the digit provided as argument. countDigit(123456789) //Output : 9 countDigit(555) II Output : 3
const myFunc2 = num => (""+num).length;
document.getElementById("ex2").innerText = myFunc2(7990);
Create a function named palindrome which checks the number whether it is same if we
read from the end. Retrun boolen value.
palindrome(12321) II true
palindrome(452103) Ilfalse
const myFunc3 = num => num == +([...(""+num)].reverse().join(""));
document.getElementById("ex3").innerText = myFunc3(12721);
Create a function which return array elements which sort and reverse order of elements.
sortReverseFunc(["a", "k", "b"]) 1/0utput : ["z", "k", "a" l;
sortReverseFunc["appIe", "zebra", "mango"] 1/0utput : ["zebra", "mango", "apple"] ;
const myFunc4 = arr => arr.sort().reverse();
document.getElementById("ex4").innerText =
myFunc4(["Apple","Zebra","Mango"]);
Create a function which checks key values of 2 objects, return a boolean value.
let objl = {name : "Jhon"};
let obj2 = {name : "Jhon"};
let obj3 = {name: "Doe"};
checkObj (objl, obj2) // true
checkObj(obj1, obj3) // false
let obj1 = { name: "Jhon", age: 18 };
let obj2 = { name: "Jhon", age: 18};
let obj3 = { name: "Doe" };
const myFunc5 = (obj1, obj2) => {
if (Object.keys(obj1).length != Object.keys(obj2).length) return false;
return Object.keys(obj1).every(ele => ele in obj2 && obj1[ele] === obj2[ele]);
}
document.getElementById("ex5").innerText = myFunc5(obj1, obj2);
Create a function to check whether an 'input* is an array or not.
//Output : false
//Output : true
const myFunc6 = arr => Array.isArray(arr);
document.getElementById("ex6").innerText = myFunc6([1,2]);
Create function to get the first element of an array as new variable and
return the name & the value of that new variable in a string.
firstElement(70, 90, 50);
firstElement([], 90, 50);
// Output : first element 70
// Output : first element []
const myFunc7 = arr =>{let [firstEle] = arr; return firstEle};
document.getElementById("ex7").innerText = myFunc7([70,90,50]);
. Create a function to get all elements of the array into a single string
using value of second argument.
let getStr(["Hello",dCoders],"+"); //O/P : "Hello + Dcoders";
let getStr(["i","am"],"indian"); //O/P : "i am indian";
const myFunc8 = (arr,sign) =>arr.join(sign);
document.getElementById("ex8").innerText = myFunc8(["hello","Coders"],"+");
Create a function to prints all the elements of nested array into single
array.
let singleArr = [1, 2,[3], [[4,5]], 6, 7; //Output :[1,2,3,4,5,6,7]
const myFunc9 = arr =>arr.flat(Infinity);
document.getElementById("ex9").innerText = myFunc9([1,2,[3],[[4,5]],6,7]);
Create a functions which takes Array as argument return new Array by
multiplying each array element with 2.
let multiplyArr([2,3,4,5])//Output :4,6,8,10;
const myFunc10 = num => num.map(e=>e*2);
document.getElementById("ex10").innerText = myFunc10([2,3,4,5]);
Create a functions to find the sum of squares of a array elements.
let getSum([1,2,3]); //Output : 14
let getSum([4, 5]); //output : 41
const myFunc11 = num => num.reduce((total, ele) => total + ele * ele, 0);
document.getElementById("ex11").innerText = myFunc11([4,5]);
Create a functions to remove negative values from an array. let RemoveNegative([1,-2,3,77,-99,5]) // O/P: [1,3,77,5]
const myFunc12 = num => num.filter(e => e >= 0)
document.getElementById("ex12").innerText = myFunc12([1,-2,3,77,-99,5]);
Create a functions which takes an array and return a sum of odd elements in array.
const myFunc13 = num => num.map(e => +e).reduce((sum, e, i) => sum + (i % 2 !== 0 ? e : 0), 0)
document.getElementById("ex13").innerText = myFunc13(["20", "100", "30", "10", "51", "1000"]);